<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <div class="text-desc">确认删除本条信息？</div>
      <el-form ref="form" size="mini" :model="form">
        <el-form-item>
          <el-checkbox v-model="isBlack" :disabled="!phone">不再采集此人发布的信息</el-checkbox>
        </el-form-item>
        <!-- 关键词不记录去掉了。2024-10-12 -->
        <!-- <el-form-item label="黑名单:">
          <div class="panel-line">
            <el-input v-model="inputWords" placeholder="请输入关键词" clearable :style="{ width: '50%', marginRight: '10px' }"> </el-input>
            <el-button type="text" icon="el-icon-plus" size="mini" @click="handleTagAdd"> 添加 </el-button>
          </div>
          <el-tag v-for="(item, index) in form.words" :key="item + index" closable style="margin-right: 6px; margin-bottom: 4px" @close="handleTagDelete(index)" disable-transitions>
            {{ item }}
          </el-tag>
        </el-form-item> -->
        <el-form-item style="margin-bottom: 0; margin-top: 40px">
          <div class="panel-line flex-end">
            <el-button @click="handleCancel">取消</el-button>
            <el-button type="primary" @click="handleSubmit" :loading="loading">确定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { apiAssetAddBlack, apiAssetDel } from '@/api/assetsPublic'

export default {
  name: 'DialogDelete',
  props: {
    id: String,
    phone: String,
  },
  data() {
    return {
      loading: false,
      inputWords: '',
      isBlack: false,
      form: {
        post_id: this.id,
        phone: this.phone,
      },
    }
  },
  mounted() {},
  destroyed() {},
  methods: {
    // 添加标签
    handleTagAdd() {
      if (!this.inputWords) {
        return
      }
      this.form.words.push(this.inputWords)
      this.inputWords = ''
    },
    // 删除标签
    handleTagDelete(index) {
      this.form.words.splice(index, 1)
    },
    // 取消
    handleCancel() {
      this.$emit('close')
    },
    // 确定
    handleSubmit() {
      this.loading = true
      apiAssetDel({ ids: [this.id] }).then(() => {
        this.loading = false
        this.$message({
          message: '删除成功',
          type: 'success',
        })
        if (this.isBlack) {
          apiAssetAddBlack(this.form)
            .then((res) => {
              this.loading = false
              this.$message({
                message: '添加黑名单成功',
                type: 'success',
              })
              setTimeout(() => {
                this.$emit('success')
              }, 1000)
            })
            .catch(() => {
              setTimeout(() => {
                this.$emit('success')
              }, 2000)
            })
        } else {
          setTimeout(() => {
            this.$emit('success')
          }, 1000)
        }
      })
    },
  },
}
</script>

<style scoped lang="scss">
.text-desc {
  width: 100%;
  padding: 10px 16px;
  background: #fef3e4;
  margin-bottom: 30px;
}
</style>
